<%-- 
    Document   : topMenuManager
    Created on : 2009-4-10, 20:16:31
    Author     : 47
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
        ljsystem.TopMenuManager.getAllMenus();
        java.util.Iterator itr = ljsystem.TopMenuManager.topMenuList.iterator();
        java.util.Iterator itr2;
        bo.MenuItem menuitem;
        bo.MenuItem menuitem2;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="/main/head.jspf" %>
        <title>系统/顶端菜单设置</title>
        <script language="javascript">
            function addmenuitem(id,name){
                document.getElementById("parentid").value=id;
                document.getElementById("parentname").value=name;
                document.getElementById("add_item_form").submit();
                return false;
            }
            function editmenuitem(id,name,uri,ordercode,parentname){
                document.getElementById("itemid").value=id;
                document.getElementById("itemname").value=name;
                document.getElementById("itemuri").value=uri;
                document.getElementById("ordercode").value=ordercode;
                document.getElementById("myparentname").value=parentname;
                document.getElementById("edit_item_form").submit();
                return false;
            }
            function editmenugroup(id,name,ordercode){
                document.getElementById("groupid").value=id;
                document.getElementById("groupname").value=name;
                document.getElementById("gpordercode").value=ordercode;
                document.getElementById("edit_group_form").submit();
                return false;
            }
            function delmenuitem(itemname){
                var r=confirm("你确定删除菜单\""+itemname+"\"吗？");
                return r;
            }
            function selectgroup(cbx){
                var itemArray=new Array();
                var i=0;
                var flag=cbx.checked;
                itemArray=document.getElementsByTagName("input");
                for(i=0;i<itemArray.length;i++){
                    if(itemArray[i].type=="checkbox"&&itemArray[i].id==cbx.id){
                        itemArray[i].checked=flag;
                    }
                }
                return false;
            }
            function selectall(flag){
                var itemArray=new Array();
                var i=0;
                itemArray=document.getElementsByTagName("input");
                for(i=0;i<itemArray.length;i++){
                    if(itemArray[i].type=="checkbox"){
                        itemArray[i].checked=flag;
                    }
                }
                return false;
            }
            function deleteselected(){
                var r=confirm("你确定删除选中的菜单项吗？");
                if(r){
                    document.getElementById("myform").submit();
                }
                return false;
            }
        </script>
    </head>
    <body>
        <%@include file="/main/bodyhead.jspf" %>
        <form id="add_item_form" action="addMenuItem.jsp" method="post">
            <input type="hidden" id="parentid" name="parentid">
            <input type="hidden" id="parentname" name="parentname">
        </form>
        <form id="edit_item_form" action="editMenuItem.jsp" method="post">
            <input type="hidden" id="itemid" name="itemid">
            <input type="hidden" id="itemname" name="itemname">
            <input type="hidden" id="itemuri" name="itemuri">
            <input type="hidden" id="ordercode" name="ordercode">
            <input type="hidden" id="myparentname" name="myparentname">
        </form>
        <form id="edit_group_form" action="editMenuGroup.jsp" method="post">
            <input type="hidden" id="groupid" name="groupid">
            <input type="hidden" id="groupname" name="groupname">
            <input type="hidden" id="gpordercode" name="gpordercode">
        </form>
        <table align="center" border="1" cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td style="text-align:right;">
                    <a href="addMenuGroup.jsp">添加菜单组</a>
                    <a href="#" onclick="return selectall(true)">全选</a>
                    <a href="#" onclick="return selectall(false)">全不选</a>
                    <a href="#" onclick="return deleteselected()">删除</a>
                </td>
            </tr>
        </table>
        <br>
        <table align="center" border="1" cellpadding="2" cellspacing="0" width="600px">
            <tr><td>
                    <table align="center" border="1" cellpadding="0" cellspacing="0" width="800px">
                        <form id="myform" action="delMenuItemdo.jsp" method="post">
                        <tr class="maintitle"><td colspan="3">以下是所有菜单项</td></tr>
                        <%
        while (itr.hasNext()) {//菜单组
            menuitem = (bo.MenuItem) itr.next();
            itr2 = menuitem.getChildren().iterator();
                        %>

                        <tr class="titleline">
                            <td colspan="2" style="text-align:left;border-right:none;">
                                <input type="checkbox" name="mid" id="<%=menuitem.getMenuId()%>" value="<%=menuitem.getMenuId()%>" onclick="selectgroup(this)">
                                <%=menuitem.getMenuName()%>
                            </td>
                            <td style="text-align:right;">
                                <a class="commonbutton" href="#" style="color:white;" onclick="addmenuitem('<%=menuitem.getMenuId()%>','<%=menuitem.getMenuName()%>');">
                                添加菜单项</a>
                                <a class="commonbutton" href="#" style="color:white;" onclick="editmenugroup('<%=menuitem.getMenuId()%>','<%=menuitem.getMenuName()%>','<%=menuitem.getOrderCode()%>')">编辑</a>
                                <a class="commonbutton" href="delMenuItemdo.jsp?mid=<%=menuitem.getMenuId()%>" onclick="return delmenuitem('<%=menuitem.getMenuName()%>');" style="color:white;">删除</a>
                            </td>
                        </tr>

                        <%
                            while (itr2.hasNext()) {//菜单项
                                menuitem2 = (bo.MenuItem) itr2.next();
                        %>
                        <tr class="infoline">
                            <td style="text-align:left;border-right:none;">
                                <input type="checkbox" name="mid" id="<%=menuitem.getMenuId()%>" value="<%=menuitem2.getMenuId()%>">
                                <%=menuitem2.getMenuName()%>
                            </td>
                            <td style="text-align:left;border-right:none;"><%=menuitem2.getMenuURI()%>
                            </td>
                            <td style="text-align:right;">
                                <a class="commonbutton" href="#" onclick="editmenuitem('<%=menuitem2.getMenuId()%>','<%=menuitem2.getMenuName()%>','<%=menuitem2.getMenuURI()%>','<%=menuitem2.getOrderCode()%>','<%=menuitem.getMenuName()%>')">
                                编辑</a>
                            <a class="commonbutton" href="delMenuItemdo.jsp?mid=<%=menuitem2.getMenuId()%>" onclick="return delmenuitem('<%=menuitem2.getMenuName()%>');">删除</a></td>
                        </tr>
                        <%}%>
                        <%}%>
                        <tr class="maintitle"><td colspan="3">&nbsp;</td></tr>
                        </form>
                    </table>
            </td></tr>
        </table>
    </body>
</html>
